Dialog generation method, apparatus, and electronic device

ABSTRACT

A dialog generation method includes: training a sequence to sequence (seq2seq)-based dialog model using a loss function including topic range constraint information; and generating a dialog using the trained dialog model. With the dialog generation method, topic range constraint information is introduced in the process of dialog model training using a loss function including the topic range constraint information, thus helping to prevent the trained model from producing low-quality meaningless replies.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation application of InternationalApplication No. PCT/CN2018/090138, filed on Jun. 6, 2018, which is basedupon and claims priority to Chinese Patent Application No.201710423859.7, filed on Jun. 7, 2017, the entire content of all ofwhich is incorporated herein by reference.

TECHNICAL FIELD

This application relates to the field of computer technologies, and inparticular, to a dialog generation method, apparatus, and electronicdevice.

TECHNICAL BACKGROUND

With the rapid development of mobile devices, smart assist relatedapplications have become increasingly common. For example, anincreasingly popular dialog assistant can dialogue with a user based onvoice, text, or other forms to answer questions raised by the user, orsimply chat with the user.

In the prior art, questions and answers in a dialog process are regardedas mapping of a question language symbol sequence to an answer languagesymbol sequence, and a sequence to sequence (seq2seq)-based dialog modelis trained using a large amount of manual dialog data with the maximumlikelihood estimation as a loss function, so that the dialog modellearns a mapping relationship between the question language symbolsequence and the answer language symbol sequence, and dialogs can beautomatically generated by the trained dialog model, therebyimplementing the dialog assistant.

However, the prior art is susceptible to high frequency reply statementswithout topic information such as “ok,” “yes,” and “got it” during themodel training, resulting in a tendency to produce these low-qualitymeaningless replies when the trained model is actually used.

SUMMARY

A dialog generation method, apparatus, and electronic device areprovided in embodiments of the specification, for solving the followingtechnical problem: the prior art is susceptible to high frequency replystatements without topic information during dialog model training,resulting in a tendency to produce low-quality meaningless replies whenthe trained model is actually used.

In one aspect, a dialog generation method comprises: training aseq2seq-based dialog model using a loss function including topic rangeconstraint information; and generating a dialog using the trained dialogmodel.

In another aspect, a dialog generation device comprises: at least oneprocessor; and a memory connected with the at least one processor,wherein the memory stores an instruction executable by the at least oneprocessor, and when executed by the at least one processor, theinstruction causes the electronic device to: train a seq2seq-baseddialog model using a loss function including topic range constraintinformation; and generate a dialog using the trained dialog model.

In still another aspect, a non-transitory computer-readable storagemedium has stored therein instructions that, when executed by aprocessor of a device, cause the device to perform a dialog generationmethod comprising: training a seq2seq-based dialog model using a lossfunction including topic range constraint information; and generating adialog using the trained dialog model.

The technical solutions adopted in the embodiments can achieve thefollowing beneficial effects: topic range constraint information isintroduced in the process of dialog model training using a loss functionincluding the topic range constraint information, thus helping toprevent the trained model from producing low-quality meaninglessreplies. Therefore, the problem in the prior art can be partially orwholly solved.

BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings, which are incorporated in and constitute apart of this specification, illustrate embodiments and, together withthe description, serve to explain the principles of the presentdisclosure.

FIG. 1 is a flowchart of a dialog generation method according to anembodiment.

FIG. 2 is a schematic diagram of a seq2seq-based dialog model accordingto an embodiment.

FIG. 3 is a schematic diagram of a dialog model training methodaccording to an embodiment.

FIG. 4 is a flowchart of a dialog model training method according to anembodiment.

FIG. 5 is a block diagram of a dialog generation apparatus according toan embodiment.

FIG. 6 is a block diagram of a dialog generation device according to anembodiment.

DETAILED DESCRIPTION

Reference will now be made in detail to embodiments, examples of whichare illustrated in the accompanying drawings. The following descriptionrefers to the accompanying drawings in which the same numbers indifferent drawings represent the same or similar elements unlessotherwise represented. The implementations set forth in the followingdescription of embodiments do not represent all implementationsconsistent with the specification. Instead, they are merely exemplary.

Embodiments of the specification provide a dialog generation method,apparatus, and electronic device. In the dialog generation method, aseq2seq-based dialog model is trained using a loss function includingtopic range constraint information based on topic reply consistency,thus preventing the trained model from producing a low-qualitymeaningless dialog. The topic range constraint information may be atleast part of a formula included in the loss function, and the at leastpart of the formula is also referred to as a topic range constraintfunction.

The topic reply consistency mainly refers to that, in a real humanconversation, dialog topics of participants are often the same orrelated, and a topic range of reply statements is also limitedcorrespondingly. For example, A mentions a weather-related topic, and itis reasonable for B to reply with a statement of the weather-relatedtopic. Generally, B will not reply with content that has nothing to dowith the weather-related topic, such as “what about this mobile phone?”

A dialog model is generally configured to simulate dialogs between realpeople as users, and thus it will be a better experience for users ifthe dialog model can generate a dialog following the topic replyconsistency.

FIG. 1 is a flowchart of a dialog generation method 100 according to anembodiment. For example, the method 100 may be implemented by a programon a server or a terminal, such as a model training program, a dialogassistant application, an instant messaging application, and the like.Also example, the method 100 may be executed by at least one of thefollowing devices that can serve as a server or a terminal: a mobilephone, a tablet computer, a smart wearable device, an on-board computer,a personal computer, a medium computer, a computer cluster, and thelike. Referring to FIG. 1, the method 100 may include the followingsteps.

In step S101, a sequence-to-sequence (seq2seq)-based dialog model istrained using a loss function including topic range constraintinformation.

In the embodiment, the topic range constraint information may be one ormore parameters related to a dialog topic in the loss function, or maybe at least part of a formula related to the topic in the loss function.

In a training process of the dialog model, parameters in the dialogmodel are adjusted according to a loss calculated based on the lossfunction, and the topic range constraint information included in theloss function also has corresponding influence on adjustment of theparameters in the dialog model, such that the content of an outputsequence of the trained dialog model is also constrained accordingly.

For example, this constraint may have two effects: firstly, the outputsequence is enabled to include topic information, rather than alow-quality meaningless dialog; and secondly, the output sequence isenabled to achieve topic reply consistency with an input sequence of thecorresponding dialog model.

In step S102, a dialog is generated using the trained dialog model.

In the embodiment, step S102 may be an operation in the process ofdialog model training, or an operation after completion of the dialogmodel training.

For example, the trained dialog model is applied to a dialog assistantapplication. The dialog model receives a statement input by a user andoutputs a reply statement; or the dialog model may output a replystatement based on a preset or automatically generated input statement;or the dialog model may directly output a preset statement withoutdepending on an input statement; and so on.

The operations involved in FIG. 1 may be performed by the same device orprogram, or by different devices or programs. For example, steps S101 toS102 are both performed by the dialog assistant application. For anotherexample, step S101 is performed by a model training program, and stepS102 is performed by the dialog assistant application; and so on.

With the method 100, topic range constraint information is introduced inthe process of dialog model training using a loss function including thetopic range constraint information, thus helping to prevent the trainedmodel from producing low-quality meaningless replies. Therefore, theproblem in the prior art can be partially or wholly solved.

FIG. 2 is a schematic diagram of a seq2seq-based dialog model 200,according to an embodiment.

The dialog model 200 may include first and second Long Short-Term Memory(LSTM) recurrent neural networks 202 and 204. The first LSTM network 202is used as an encoder for processing an input dialog word sequence X,such as {x1, x2, x3, x4, x5}, and the second LSTM network 204 is used asa decoder for generating a reply word sequence Y, such as {y1, y2, y3}.For example, each of x1, x2, x3, x4, and x5 may represent a character orword in a sentence, and each of y1, y2, and y3 may represent a characteror word in a reply to the sentence. Also for example, “Eos” (End ofsequence) may represent a symbol indicating an end of a sequence. In anactual application, a loss function (i.e., an objective function) of theseq2seq-based dialog model 200 may adopt a Maximum Likelihood Estimate(MLE), as shown in the following Formula 1:

Cost=log p(Y|X);  Formula 1.

In the embodiment, a topic range constraint function may be added toFormula 1, and then used for training the dialog model 200. In otherembodiments where the MLE is not adopted, Formula 1 can be replacedcorrespondingly. Illustration is made with reference to FIG. 3 still bytaking the MLE as an example.

FIG. 3 is a schematic diagram of a dialog model training method 300,according to an embodiment. As can be seen, compared with FIG. 2, thetopic range constraint function and a corresponding loss calculation areadded in FIG. 3.

FIG. 4 is a flowchart of the dialog model training method 300 (FIG. 3)according to an embodiment. Referring to FIGS. 3 and 4, the method 300may include the following steps.

In step 402, a topic model is trained to obtain multiple first topicvectors 302.

In step 404, a first topic vector 304 (denoted as: T_(topic-id) ^(θ))corresponding to a reply word sequence Y is determined according to thetrained topic model.

In step 406, operations of pooling, such as average pooling 306, and amulti-layer perceptron (MLP) transformation 308 are performed on varioushidden-state output data during processing in the dialog modelcorresponding to Y, thus obtaining a second topic vector 310 (denotedas: T^(V)) corresponding to Y. For example, an MLP is a class ofartificial neural network. An MLP may include three layers of nodes: aninput layer, a hidden layer, and an output layer. Also for example, ahidden state of an item (e.g., character, word, etc.) in a sequence maybe used to encode/decode a next item (e.g., next character, word, etc.)in the sequence. In some embodiments, existing MLP transformationtechniques may be used in step 406.

In step 408, a first similarity 312 (denoted as: S_(t)=Relevance (T^(V),T_(topic-id) ^(θ))) between the second topic vector corresponding to Yand the first topic vector 304 corresponding to Y and a secondsimilarity 314 (denoted as: S_(t)=Relevance (T^(V), T _(topic-id) ^(θ)))between the second topic vector corresponding to Y and an irrelevanttopic vector 316 (denoted as: T _(topic-id) ^(θ)) are calculated, whereRelevance( ) denotes a similarity calculation function, such as a cosinesimilarity function Cosine( ).

In step 410, the first similarity 312 and the second similarity 314 aresubstituted into the loss function including the topic range constraintfunction to calculate a loss, and the dialog model is adjusted accordingto the loss.

Further illustration is made as follows.

First, a topic model is trained in an unsupervised manner using a dialogtraining corpus. The topic model may be, for example, a Latent DirichletAllocation (LDA) model, a Kmeans model, or the like. The dialog trainingcorpus may be a set of dialogs, e.g., collected from real conversations.By training the topic model, multiple topics can be extracted from thedialog training corpus, and multiple topic vectors are generatedcorrespondingly, which are referred to as first topic vectors 302 eachrepresenting a topic. Topic IDs can be used to identify the first topicvectors 302. In some embodiments, the first topic vector may be a densevector similar to word embedding, wherein the word embedding refers toconverting a word into a word vector.

Then, according to the trained topic model, a first topic vector 304corresponding to the reply word sequence Y can be obtained. Assumingthat there is only one central meaning in one sentence, Y onlycorresponds to one topic ID, and corresponds to only one first topicvector correspondingly.

After that, hidden-state output data of Y during each step of the LSTMmodeling is input for average pooling 306, and then transformed by theMLP 308 to obtain another topic vector expression of Y, which isreferred to as a second topic vector 310 corresponding to Y. The MLP maybe a multi-layer neural network, such as fully connected Deep NeuralNetworks (DNNs), etc.

It can be considered that the second topic vector 310 corresponding to Yshould be similar to the first topic vector 304 corresponding to Y inthe semantic space, compared to a first topic vector 316 correspondingto another irrelevant topic ID. Based on such consideration, a lossfunction including topic range constraint information is defined and,for example, is shown in Formula 2 below:

Cost′=log p(Y|X)+λ*log(1+e ^(−(S) ^(t) ^(-S) ^(t) ⁾);  Formula 2,

where λ is a weight coefficient, S_(t) represents a similarity betweenthe second topic vector 310 corresponding to Y and the first topicvector 304 corresponding to Y, and S _(t) represents a similaritybetween the second topic vector 310 corresponding to Y and an irrelevanttopic vector 316. The irrelevant topic vector 316 is a vector among thefirst topic vectors 302 other than the first topic vector 304corresponding to Y, and a topic corresponding to the irrelevant topicvector is irrelevant to the topic corresponding to Y.

The similarity may be, for example, a cosine similarity, or data thatcan measure the similarity between vectors, such as a distance betweenvectors.

Finally, based on Formula 2, the corresponding loss may be calculatedand the dialog model may be adjusted. As a result, the dialog model canbe repeatedly trained using multiple training samples until the trainingconverges.

It should be noted that the implementation in FIG. 3 is only exemplary.Based on the method 300, some steps involved in the training in themethod 100 (FIG. 1) are further illustrated below.

In the method 100, a step of training a topic model using a dialogtraining corpus to obtain multiple first topic vectors each representinga topic may be further performed before the step S101 of training theseq2seq-based dialog model.

In the example of FIG. 3, the topic model is trained in an unsupervisedmanner, which is advantageous in that the training can be efficientlyperformed with a large amount of dialog training corpus, without theneed of manually adding topic labels to the dialog training corpus.Therefore, the cost can be reduced and it is not easy to miss topics.The topic model may also be trained in a supervised manner.

In the method 100, the step S101 of training the seq2seq-based dialogmodel using the loss function including the topic range constraintinformation may include: inputting a training sequence into theseq2seq-based dialog model for processing to obtain various hidden-stateoutput data output during the processing and an output sequence obtainedafter the processing: generating a second topic vector corresponding tothe output sequence according to the various hidden-state output data;inputting the output sequence into the trained topic model forprocessing to obtain a first topic vector corresponding to the outputsequence among the multiple first topic vectors; calculating a lossusing the loss function including topic range constraint informationaccording to the first and second topic vectors corresponding to theoutput sequence; and adjusting the dialog model according to the loss.

In the example of FIG. 3, the training sequence is X, and the outputsequence is Y.

Further, the generating a second topic vector corresponding to theoutput sequence according to the various hidden-state output data mayhave a variety of specific implementation manners.

For example, the manner in the example of FIG. 3 is: pooling the varioushidden-state output data; and inputting data obtained after the poolinginto an MLP for processing to obtain the second topic vectorcorresponding to the output sequence. The pooling takes average poolingas an example, without excluding the possibility of using anotherpooling manner other than the average pooling.

In addition, the various hidden-state output data may be mapped inanother set mapping manner other than using the MLP to obtain the secondtopic vector corresponding to the output sequence.

Further, the calculating a loss using the loss function including topicrange constraint information according to the first and second topicvectors corresponding to the output sequence may include: calculating afirst similarity between the second topic vector corresponding to theoutput sequence and the first topic vector corresponding to the outputsequence; calculating a second similarity between the second topicvector corresponding to the output sequence and an irrelevant topicvector, wherein the irrelevant topic vector is a vector in the multiplefirst topic vectors other than the first topic vector corresponding tothe output sequence; and substituting the first similarity and thesecond similarity into the loss function including topic rangeconstraint information to calculate the loss, wherein the topic rangeconstraint information is a formula including parameters correspondingto the first similarity and the second similarity.

In the example of FIG. 3, the parameter corresponding to the firstsimilarity is S_(t), the parameter corresponding to the secondsimilarity is S _(t) , the loss function including the topic rangeconstraint information is Formula 2, and the topic range constraintinformation is λ*log(1+e^(−(S) ^(t) ^(−S) ^(t) ⁾).

It should be noted that Formula 2 is exemplary, and other loss functionsincluding the topic range constraint information other than Formula 2may be constructed based on the parameters S_(t) and/or S _(t) . Ingeneral, for the topic range constraint information including theparameters S_(t) and S _(t) , the greater S_(t) is compared with S _(t), the smaller the loss portion corresponding to the topic rangeconstraint information in the calculated loss is.

FIG. 5 is a block diagram of a dialog generation apparatus 500corresponding to the method 100 (FIG. 1), according to an embodiment.The apparatus 500 may include: a training module 501 training aseq2seq-based dialog model using a loss function including topic rangeconstraint information; and a generation module 502 generating a dialogusing the trained dialog model.

In some embodiments, before training the seq2seq-based dialog model, thetraining module 501 further trains a topic model using a dialog trainingcorpus to obtain multiple first topic vectors each representing a topic.

In some embodiments, the training module 501 training a seq2seq-baseddialog model using a loss function including topic range constraintinformation includes: the training module 501 inputting a trainingsequence into the seq2seq-based dialog model for processing to obtainvarious hidden-state output data output during the processing and anoutput sequence obtained after the processing; generating a second topicvector corresponding to the output sequence according to the varioushidden-state output data; inputting the output sequence into the trainedtopic model for processing to obtain a first topic vector correspondingto the output sequence among the multiple first topic vectors;calculating a loss using the loss function including topic rangeconstraint information according to the first and second topic vectorscorresponding to the output sequence; and adjusting the dialog modelaccording to the loss.

In some embodiments, the training module 501 generating a second topicvector corresponding to the output sequence according to the varioushidden-state output data includes: the training module 501 pooling thevarious hidden-state output data; and inputting data obtained after thepooling into an MLP for processing to obtain the second topic vectorcorresponding to the output sequence.

In some embodiments, the training module 501 calculating a loss usingthe loss function including topic range constraint information accordingto the first and second topic vectors corresponding to the outputsequence includes: the training module 501 calculating a firstsimilarity between the second topic vector corresponding to the outputsequence and the first topic vector corresponding to the outputsequence; calculating a second similarity between the second topicvector corresponding to the output sequence and an irrelevant topicvector, wherein the irrelevant topic vector is a vector in the multiplefirst topic vectors other than the first topic vector corresponding tothe output sequence; and substituting the first similarity and thesecond similarity into the loss function including topic rangeconstraint information to calculate the loss, wherein the topic rangeconstraint information is a formula including parameters correspondingto the first similarity and the second similarity.

FIG. 6 is a block diagram of a dialog generation device 600, accordingto an embodiment. The device 600 may be a server or a terminal, such asa mobile phone, a tablet computer, a smart wearable device, an on-boardcomputer, a personal computer, a medium computer, a computer cluster,and the like. The device 600 may include a processor 602, a memory 604,and other hardware 606, such as a chip for transmitting and receivingwireless signals, a board card for implementing a network communicationinterface, an input/output interface, etc.

The processor 602 may include one or more dedicated processing units,application-specific integrated circuits (ASICs), field-programmablegate arrays (FPGAs), or various other types of processors or processingunits. The processor 602 is coupled with the memory 604 and isconfigured to execute instructions stored in the memory 604 to performthe above described methods.

The memory 604 may include a permanent memory, a non-permanent memory, arandom access memory (RAM) and/or a non-volatile memory (such as aread-only memory (ROM) or a flash memory (flash RAM)), etc. The memory604 stores an instruction executable by the processor 602, and whenexecuted by the processor 602, the instruction causes the device 600 to:train a seq2seq-based dialog model using a loss function including topicrange constraint information; and generate a dialog using the traineddialog model.

In some embodiments, there is provided a computer program product, suchas a non-transitory computer-readable storage medium havingcomputer-readable program instructions thereon for causing a processorto carry out the above-described methods.

The apparatus, device, and non-transitory computer storage mediumcorrespond to the methods, and also have beneficial technical effectssimilar to those in the corresponding methods, as described above.

Each of the above described methods, modules, and units may beimplemented as software, or hardware, or a combination of software andhardware. For example, a Programmable Logic Device (PLD) (for example, aField Programmable Gate Array (FPGA)) is an integrated circuit, andlogic functions thereof are determined by a user programming device.Designers program by themselves to integrate a digital system into aPLD, without having a chip manufacturer to design and manufacture adedicated integrated circuit chip. Moreover, at present, the programmingis mostly implemented by using logic compiler software, instead ofmanually manufacturing an integrated circuit chip. The software issimilar to a software complier for developing and writing a program, andoriginal codes before compiling also need to be written in a specificprogramming language, which is referred to as a Hardware DescriptionLanguage (HDL). There are not just one, but many types of HDLs, such asAdvanced Boolean Expression Language (ABEL), Altera Hardware DescriptionLanguage (AHDL), Confluence, Cornell University Programming Language(CUPL), HDCal, Java Hardware Description Language (JHDL), Lava, Lola,MyHDL, PALASM, and Ruby Hardware Description Language (RHDL), amongwhich Very-High-Speed Integrated Circuit Hardware Description Language(VHDL) and Verilog are most commonly used now. Those skilled in the artwill know that a hardware circuit for implementing the logic methodprocedure may be easily obtained only by slightly logically programmingthe method procedure using the above several hardware descriptionlanguages and programming the method procedure into an integratedcircuit.

A controller may be implemented in any suitable manner in the abovedescribed devices. For example, the controller may be in the form of amicroprocessor or a processor and a computer-readable medium storingcomputer-readable program codes (for example, software or firmware)executable by the (micro)processor, a logic gate, a switch, anApplication Specific Integrated Circuit (ASIC), a programmable logiccontroller, and an embedded micro-controller. Examples of the controllerinclude, but are not limited to, the following micro-controllers: ARC625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320.A memory controller may also be implemented as a part of control logicof a memory. Those skilled in the art also know that, in addition toimplementing the controller by using pure computer-readable programcodes, the method steps may be logically programmed to enable thecontroller to implement the same function in the form of a logic gate, aswitch, an application specific integrated circuit, a programmable logiccontroller and an embedded microcontroller. Therefore, such a controllermay be considered as a hardware component, and apparatuses includedtherein and configured to implement various functions may also beconsidered as structures inside the hardware component. Alternatively,further, the apparatuses configured to implement various functions maybe considered as both software modules for implementing the method andstructures inside the hardware component.

The device, apparatus, module or unit illustrated in the foregoingembodiments can be implemented by a computer chip or an entity, orimplemented by a product having a specific function. A typicalimplementation device is a computer. For example, the computer may be apersonal computer, a laptop computer, a cellular phone, a camera phone,a smart phone, a personal digital assistant, a media player, anavigation device, an email device, a game console, a tablet computer, awearable device, or a combination of any of these devices.

For ease of description, the apparatus is divided into various modulesbased on functions, and the modules are described separately. In anembodiment, functions of the various modules can also be implemented inone or more pieces of software and/or hardware.

Those skilled in the art should understand that the embodiments of thespecification may be provided as a method, a device, or a computerprogram product. Therefore, the embodiments may be implemented in a formof a complete hardware embodiment, a complete software embodiment, or anembodiment combining software and hardware.

Some embodiments are described with reference to flowcharts and/or blockdiagrams of the method, device (system) and computer program product. Itshould be understood that a computer program instruction may be used toimplement each process and/or block in the flowcharts and/or blockdiagrams and combinations of processes and/or blocks in the flowchartsand/or block diagrams. These computer program instructions may beprovided to a general-purpose computer, a special-purpose computer, anembedded processor, or a processor of another programmable dataprocessing device to generate a machine, so that the instructionsexecuted by the computer or the processor of another programmable dataprocessing device generate an apparatus configured to implement aspecified function in one or more processes in the flowcharts and/or inone or more blocks in the block diagrams.

These computer program instructions may also be stored in acomputer-readable memory that can guide a computer or anotherprogrammable data processing device to work in a particular manner, suchthat the instructions stored in the computer-readable memory generate anarticle of manufacture that includes an instruction apparatus. Theinstruction apparatus implements a function specified in one or moreprocesses in the flowcharts and/or in one or more blocks in the blockdiagrams.

These computer program instructions may also be loaded onto a computeror another programmable data processing device, such that a series ofoperation steps are performed on the computer or another programmabledevice, thus generating computer-implemented processing. Therefore, theinstructions executed on the computer or another programmable deviceprovide steps for implementing a function specified in one or moreprocesses in the flowcharts and/or in one or more blocks in the blockdiagrams.

The computer-readable storage medium may include permanent andnon-permanent media as well as movable and non-movable media, and mayimplement information storage by means of any method or technology. Theinformation may be a computer-readable instruction, a data structure,and a module of a program or other data. Examples of thecomputer-readable storage medium include, but are not limited to, aphase change memory (PRAM), a static random access memory (SRAM), adynamic random access memory (DRAM), other types of RAMs, a ROM, anelectrically erasable programmable read-only memory (EEPROM), a flashmemory or other memory technologies, a compact disk read-only memory(CD-ROM), a digital versatile disc (DVD) or other optical storages, acassette tape, a magnetic tape/magnetic disk storage or other magneticstorage devices, or any other non-transmission medium, and can be usedto store information accessible to the computing device. According tothe definition in this specification, the computer-readable medium doesnot include transitory media, such as a modulated data signal and acarrier.

It should be further noted that the terms “include,” “comprise” or othervariations thereof are intended to cover non-exclusive inclusion, sothat a process, method, article or device including a series of elementsnot only includes the elements, but also includes other elements notclearly listed, or further includes elements inherent to the process,method, article or device. In the absence of more limitations, anelement defined by “including a/an . . . ” does not exclude that theprocess, method, article or device including the element further hasother identical elements.

The above described methods may be implemented by instructions executedby a computer, for example, a program module. Generally, the programmodule includes a routine, a program, an object, an assembly, a datastructure, and the like for executing a specific task or implementing aspecific abstract data type. The above described methods may also beimplemented in distributed computing environments. In the distributedcomputing environments, a task is executed by remote processing devicesconnected through a communications network. In the distributed computingenvironments, the program module may be located in local and remotecomputer storage media including a storage device.

Although the specification has been described in conjunction withspecific embodiments, many alternatives, modifications and variationswill be apparent to those skilled in the art. Accordingly, the followingclaims embrace all such alternatives, modifications and variations thatfall within the terms of the claims.

1. A dialog generation method, comprising: training a sequence tosequence (seq2seq)-based dialog model using a loss function comprisingtopic range constraint information; and generating a dialog using thetrained dialog model.
 2. The method of claim 1, wherein before thetraining a seq2seq-based dialog model, the method further comprises:training a topic model using a dialog training corpus to obtain multiplefirst topic vectors each representing a topic.
 3. The method of claim 2,wherein the training a seq2seq-based dialog model using a loss functioncomprising topic range constraint information comprises: inputting atraining sequence into the seq2seq-based dialog model for processing toobtain various hidden-state output data output during the processing andan output sequence obtained after the processing; generating a secondtopic vector corresponding to the output sequence according to thevarious hidden-state output data; inputting the output sequence into thetrained topic model for processing to obtain a first topic vectorcorresponding to the output sequence among the multiple first topicvectors; calculating a loss using the loss function comprising topicrange constraint information according to the first and second topicvectors corresponding to the output sequence; and adjusting the dialogmodel according to the loss.
 4. The method of claim 3, wherein thegenerating a second topic vector corresponding to the output sequenceaccording to the various hidden-state output data comprises: pooling thevarious hidden-state output data; and inputting data obtained after thepooling into a multi-layer perceptron for processing to generate thesecond topic vector corresponding to the output sequence.
 5. The methodof claim 3, wherein the calculating a loss using the loss functioncomprising topic range constraint information according to the first andsecond topic vectors corresponding to the output sequence comprises:calculating a first similarity between the second topic vectorcorresponding to the output sequence and the first topic vectorcorresponding to the output sequence; calculating a second similaritybetween the second topic vector corresponding to the output sequence andan irrelevant topic vector, wherein the irrelevant topic vector is avector in the multiple first topic vectors other than the first topicvector corresponding to the output sequence; and substituting the firstsimilarity and the second similarity into the loss function comprisingtopic range constraint information to calculate the loss, wherein thetopic range constraint information is a formula comprising parameterscorresponding to the first similarity and the second similarity.
 6. Adialog generation device, comprising: a processor; and a memory forstoring instructions executable by the processor; wherein the processoris configured to: train a sequence to sequence (seq2seq)-based dialogmodel using a loss function comprising topic range constraintinformation; and generate a dialog using the trained dialog model. 7.The device of claim 6, wherein before training the seq2seq-based dialogmodel, the processor is further configured to train a topic model usinga dialog training corpus to obtain multiple first topic vectors eachrepresenting a topic.
 8. The device of claim 7, wherein in training theseq2seq-based dialog model using the loss function comprising topicrange constraint information, the processor is further configured to:input a training sequence into the seq2seq-based dialog model forprocessing to obtain various hidden-state output data output during theprocessing and an output sequence obtained after the processing;generate a second topic vector corresponding to the output sequenceaccording to the various hidden-state output data; input the outputsequence into the trained topic model for processing to obtain a firsttopic vector corresponding to the output sequence among the multiplefirst topic vectors; calculate a loss using the loss function comprisingtopic range constraint information according to the first and secondtopic vectors corresponding to the output sequence; and adjust thedialog model according to the loss.
 9. The device of claim 8, wherein ingenerating a second topic vector corresponding to the output sequenceaccording to the various hidden-state output data, the processor isfurther configured to: pool the various hidden-state output data; andinput data obtained after the pooling into a multi-layer perceptron forprocessing to generate the second topic vector corresponding to theoutput sequence.
 10. The device of claim 8, wherein in calculating theloss using the loss function comprising topic range constraintinformation according to the first and second topic vectorscorresponding to the output sequence, the processor is furtherconfigured to: calculate a first similarity between the second topicvector corresponding to the output sequence and the first topic vectorcorresponding to the output sequence; calculate a second similaritybetween the second topic vector corresponding to the output sequence andan irrelevant topic vector, wherein the irrelevant topic vector is avector in the multiple first topic vectors other than the first topicvector corresponding to the output sequence; and substitute the firstsimilarity and the second similarity into the loss function comprisingtopic range constraint information to calculate the loss, wherein thetopic range constraint information is a formula comprising parameterscorresponding to the first similarity and the second similarity.
 11. Anon-transitory computer-readable storage medium having stored thereininstructions that, when executed by a processor of a device, cause thedevice to perform a dialog generation method, the method comprising:training a sequence to sequence (seq2seq)-based dialog model using aloss function comprising topic range constraint information; andgenerating a dialog using the trained dialog model.
 12. Thenon-transitory computer-readable storage medium of claim 11, whereinbefore the training a seq2seq-based dialog model, the method furthercomprises: training a topic model using a dialog training corpus toobtain multiple first topic vectors each representing a topic.
 13. Thenon-transitory computer-readable storage medium of claim 12, wherein thetraining a seq2seq-based dialog model using a loss function comprisingtopic range constraint information comprises: inputting a trainingsequence into the seq2seq-based dialog model for processing to obtainvarious hidden-state output data output during the processing and anoutput sequence obtained after the processing; generating a second topicvector corresponding to the output sequence according to the varioushidden-state output data; inputting the output sequence into the trainedtopic model for processing to obtain a first topic vector correspondingto the output sequence among the multiple first topic vectors;calculating a loss using the loss function comprising topic rangeconstraint information according to the first and second topic vectorscorresponding to the output sequence; and adjusting the dialog modelaccording to the loss.
 14. The non-transitory computer-readable storagemedium of claim 13, wherein the generating a second topic vectorcorresponding to the output sequence according to the varioushidden-state output data comprises: pooling the various hidden-stateoutput data; and inputting data obtained after the pooling into amulti-layer perceptron for processing to generate the second topicvector corresponding to the output sequence.
 15. The non-transitorycomputer-readable storage medium of claim 13, wherein the calculating aloss using the loss function comprising topic range constraintinformation according to the first and second topic vectorscorresponding to the output sequence comprises: calculating a firstsimilarity between the second topic vector corresponding to the outputsequence and the first topic vector corresponding to the outputsequence; calculating a second similarity between the second topicvector corresponding to the output sequence and an irrelevant topicvector, wherein the irrelevant topic vector is a vector in the multiplefirst topic vectors other than the first topic vector corresponding tothe output sequence; and substituting the first similarity and thesecond similarity into the loss function comprising topic rangeconstraint information to calculate the loss, wherein the topic rangeconstraint information is a formula comprising parameters correspondingto the first similarity and the second similarity.